﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head><link rel="stylesheet" href="${ctx}/common/common.css">
    <title>Title</title>
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all">
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>
    
    <script src="${ctx}/common/plugins/jquery-1.10.2.min.js"></script>
</head>
<body>
<form class="layui-form" action="${ctx}/material/materialSave" method="post" enctype="multipart/form-data">
    <input type="hidden" name="id" value="${material.id}"/>
    <div class="layui-form-item layui-col-md5" style="margin-top: 50px">
        <label class="layui-form-label">物料名称<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="name" value="${material.name}"  lay-verify="required"  placeholder="请输入物料名称" autocomplete="on"   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">物料类别<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="materialType"  value="${materialType.described}" id="materialsBtn" readonly lay-verify="required"   placeholder="请选择物料类别" autocomplete="off" class="layui-input">
            <input type="hidden" name="tDId" id="t_d_id" value="${material.tDId}"  lay-verify="required"   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">物料编号<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="code" value="${material.code}"  lay-verify="required|number"   placeholder="请输入物料编号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">规格<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="specifications" value="${material.specifications}" lay-verify="required"   placeholder="请输入规格" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">参考价格<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="price" value="${material.price}" lay-verify="required|number"   placeholder="请输入参考价格" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">有效期天数<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="expiryDate" value="${material.expiryDate}" lay-verify="required|number"   placeholder="请输入有效期天数" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">生产厂家<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="manufacturer" value="${material.manufacturer}" lay-verify="required"   placeholder="请输入生产厂家" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">生产许可</label>
        <div class="layui-input-block">
            <input type="text" name="pLicense" value="${material.pLicense}"  placeholder="请输入生产许可编号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">执行标准</label>
        <div class="layui-input-block">
            <input type="text" name="perfStandard" value="${material.perfStandard}"   placeholder="请输入执行标准" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">单件重量<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="singleWeight" value="${material.singleWeight}" lay-verify="required|number"   placeholder="请输入单件重量" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">单件容量<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="singleCapacity" value="${material.singleCapacity}" lay-verify="required|number"   placeholder="请输入单件容量" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">单件体积<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="singleVolume" value="${material.singleVolume}" lay-verify="required|number"   placeholder="请输入单件体积" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5" id="packageCodeDiv" ${materialType.classify eq 'packagingClassify' ? '':'style="display: none"'} >
        <label class="layui-form-label">是否生成码</label>
        <div class="layui-input-block">
            <input type="checkbox" id="tMcValue"   ${material.createCode eq '1'?'checked':''}  lay-skin="switch" name="createCode" value="1"  lay-text="是|否" title="是否生成码">
            <input type="hidden" name="tMcId"  id="tMcId" value="${material.tMcId}"    autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">单位<span style="color: red">*</span></label>
        <div class="layui-input-block">
            <input type="text" name="unit" value="${material.unit}" lay-verify="required|maxNumber"  placeholder="单位" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-col-md5">
        <label class="layui-form-label">物料图片</label>
        <div class="layui-input-block" id="materialsImg">
            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <c:if test="${!empty material.mTimg && fn:length(material.mTimg)>0  && material.mTimg != 'null' }">
                <img src="${ctx}${material.mTimg}" class="imga" style="width: 100px;height: 100px;">
            </c:if>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="formBtn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <button type="button" id="rollback" class="layui-btn layui-btn-primary">返回</button>
        </div>
    </div>
</form>
<script>
    var form = null;
    layui.use('form', function () {
        form = layui.form;
        var $ = layui.$;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            $("#tMcId").val($("#t_d_id").val())
            layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
        });
        form.verify({
            maxNumber: function (value) {
                if (value.length > 3) {
                    return '长度不能大于3位';
                }
            }
        })

        $("#materialsBtn").on("click",function(){
            layer.open({
                type: 2,
                title: '物料信息',
                shadeClose: true,
                offset: '10px',
                shade: 0.8,
                area: ['40%', '80%'],
                content: '${ctx}/material/queryMaterialsTree?material=add' //iframe的url
            });
        })
    });

    layui.use('upload', function(){
        var $ = layui.$;
        var upload = layui.upload;
        var count=0;
        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/upload/' //上传接口
            ,accept: 'images'
            ,multiple:false
            ,auto:false
            ,bindAction:"#uploadFile"
            ,choose:function(obj){
                //选择文件
                //将每次选择的文件追加到文件队列
                var files = obj.pushFile();
                //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                obj.preview(function(index, file, result) {
                    $(".imga").remove();
                    $("#materialsImg").append('<img src="'+result+'" class="imga" style="width: 100px;height: 100px;">');
                })
            }
        });
    });
    document.getElementById("rollback").addEventListener("click",function(){
        window.history.back();
    })
</script>
</body>
</html>



